﻿Imports System.Data.SqlClient

Public Class clsE_Productividad
    Private mintIdProductividad As Integer
    Private mintIdAutobus As Integer
    Private mstrNoEconomico As String
    Private mintIdOperador As Integer
    Private mstrNombreOperador As String
    Private mdatFecha As Date
    Private mintDia As Integer
    Private mintMes As Integer
    Private mintAnio As Integer
    Private mdblLiquidacion As Double
    Private mdblOptocontrol As Double
    Private mdblCumplimiento As Double
    Private mintVentas As Integer
    Private mintMovilidad As Integer
    Private mintBloqueos As Integer
    Private mdblBloqueoPorcentaje As Double
    Private mdblTotal As Double
    Public Property IdProductividad() As Integer
        Get
            Return mintIdProductividad
        End Get
        Set(ByVal value As Integer)
            mintIdProductividad = value
        End Set
    End Property
    Public Property IdAutobus() As Integer
        Get
            Return mintIdAutobus
        End Get
        Set(ByVal value As Integer)
            mintIdAutobus = value
        End Set
    End Property

    Public Property NoEconomico() As String
        Get
            Return mstrNoEconomico
        End Get
        Set(ByVal value As String)
            mstrNoEconomico = value
        End Set
    End Property
    Public Property IdOperador() As Integer
        Get
            Return mintIdOperador
        End Get
        Set(ByVal value As Integer)
            mintIdOperador = value
        End Set
    End Property
    Public Property NombreOperador() As String
        Get
            Return mstrNombreOperador
        End Get
        Set(ByVal value As String)
            mstrNombreOperador = value
        End Set
    End Property
    Public Property Fecha() As Date
        Get
            Return mdatFecha
        End Get
        Set(ByVal value As Date)
            mdatFecha = value
        End Set
    End Property
    Public Property Dia() As Integer
        Get
            Return mintDia
        End Get
        Set(ByVal value As Integer)
            mintDia = value
        End Set
    End Property
    Public Property Mes() As Integer
        Get
            Return mintMes
        End Get
        Set(ByVal value As Integer)
            mintMes = value
        End Set
    End Property
    Public Property Anio() As Integer
        Get
            Return mintAnio
        End Get
        Set(ByVal value As Integer)
            mintAnio = value
        End Set
    End Property
    Public Property Liquidacion() As Double
        Get
            Return mdblLiquidacion
        End Get
        Set(ByVal value As Double)
            mdblLiquidacion = value

        End Set
    End Property
    Public Property Optocontrol() As Double
        Get
            Return mdblOptocontrol
        End Get
        Set(ByVal value As Double)
            mdblOptocontrol = value

        End Set
    End Property
    Public Property Cumplimiento() As Double
        Get
            Return mdblCumplimiento
        End Get
        Set(ByVal value As Double)
            mdblCumplimiento = value

        End Set
    End Property
    Public Property Ventas() As Integer
        Get
            Return mintVentas
        End Get
        Set(ByVal value As Integer)
            mintVentas = value
        End Set
    End Property
    Public Property Movilidad() As Integer
        Get
            Return mintMovilidad
        End Get
        Set(ByVal value As Integer)
            mintMovilidad = value
        End Set
    End Property
    Public Property Bloqueos() As Integer
        Get
            Return mintBloqueos
        End Get
        Set(ByVal value As Integer)
            mintBloqueos = value
        End Set
    End Property
    Public Property BloqueoPorcentaje() As Double
        Get
            Return mdblBloqueoPorcentaje
        End Get
        Set(ByVal value As Double)
            mdblBloqueoPorcentaje = value

        End Set
    End Property
    Public Property Total() As Double
        Get
            Return mdblTotal
        End Get
        Set(ByVal value As Double)
            mdblTotal = value
        End Set
    End Property
    Public Sub New()
        mintIdProductividad = 0
        mintIdAutobus = 0
        mstrNoEconomico = ""
        mintIdOperador = 0
        mstrNombreOperador = ""
        mdatFecha = Now()
        mintDia = 0
        mintMes = 0
        mintAnio = 0
        mdblLiquidacion = 0
        mdblOptocontrol = 0
        mdblCumplimiento = 0
        mintVentas = 0
        mintMovilidad = 0
        mintBloqueos = 0
        mdblBloqueoPorcentaje = 0
        mdblTotal = 0
    End Sub
    Public Sub Insertar()
        Dim sql As String = "Insert Into E_Productividad (" & _
                            "IdAutobus," & _
                            "NoEconomico," & _
                            "IdOperador," & _
                            "NombreOperador," & _
                            "Fecha," & _
                            "Dia," & _
                            "Mes," & _
                            "Anio," & _
                            "Liquidacion," & _
                            "Optpcontrol," & _
                            "Cumplimiento," & _
                            "Ventas," & _
                            "Movilidad," & _
                            "Bloqueos," & _
                            "BloqueosPorcentaje," & _
                            "Total) " & _
                            "VALUES (" & _
                            "@IdAutobus," & _
                            "substring(@NoEconomico,1,100)," & _
                            "@IdOperador," & _
                            "substring(@NombreOperador,1,150)," & _
                            "@Fecha," & _
                            "@Dia," & _
                            "@Mes," & _
                            "@Anio," & _
                            "@Liquidacion," & _
                            "@Optocontrol," & _
                            "@Cumplimiento," & _
                            "@Ventas," & _
                            "@Movilidad," & _
                            "@Bloqueos," & _
                            "@BloqueoPorcentaje," & _
                            "@Total) "

        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        Dim Command As New SqlCommand(sql, cnConn)

        Command.Parameters.AddWithValue("IdAutobus", mintIdAutobus)
        Command.Parameters.AddWithValue("NoEconomico", mstrNoEconomico)
        Command.Parameters.AddWithValue("IdOperador", mintIdOperador)
        Command.Parameters.AddWithValue("NombreOperador", mstrNombreOperador)
        Command.Parameters.AddWithValue("Fecha", mdatFecha)
        Command.Parameters.AddWithValue("Dia", mintDia)
        Command.Parameters.AddWithValue("Mes", mintMes)
        Command.Parameters.AddWithValue("Anio", mintAnio)
        Command.Parameters.AddWithValue("Liquidacion", mdblLiquidacion)
        Command.Parameters.AddWithValue("Optocontrol", mdblOptocontrol)
        Command.Parameters.AddWithValue("Cumplimiento", mdblCumplimiento)
        Command.Parameters.AddWithValue("Ventas", mintVentas)
        Command.Parameters.AddWithValue("Movilidad", mintMovilidad)
        Command.Parameters.AddWithValue("Bloqueos", mintBloqueos)
        Command.Parameters.AddWithValue("BloqueoPorcentaje", mdblBloqueoPorcentaje)
        Command.Parameters.AddWithValue("Total", mdblTotal)

        cnConn.Open()
        Dim RowsAffected As Integer
        Try
            RowsAffected = Command.ExecuteNonQuery
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Aviso")
        End Try

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible insertar el registro de productividad", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If
    End Sub
    Sub Actualizar()
        Dim strSqlQry As String
        Dim cnConn As New SqlConnection
        cnConn.ConnectionString = CitraConnection

        strSqlQry = "Update E_Productividad Set " & _
                            "IdAutobus=@IdAutobus," & _
                            "NoEconomico=substring(@NoEconomico,1,50)," & _
                            "IdOperador=@IdOperador," & _
                            "NombreOperador=substring(@NombreOperador,1,50)," & _
                            "Fecha=@Fecha," & _
                            "Dia=@Dia," & _
                            "Mes=@Mes," & _
                            "Anio=@Anio," & _
                            "Liquidacion=@Liquidacion," & _
                            "Optpcontrol=@Optocontrol," & _
                            "Cumplimiento=@Cumplimiento," & _
                            "Ventas=@Ventas," & _
                            "Movilidad=@Movilidad," & _
                            "Bloqueos=@Bloqueos," & _
                            "BloqueosPorcentaje=@BloqueoPorcentaje," & _
                            "Total=@Total " & _
                            " Where IdProductividad=@IdProductividad"


        Dim Command As New SqlCommand(strSqlQry, cnConn)
        Command.Parameters.AddWithValue("IdProductividad", mintIdProductividad)
         Command.Parameters.AddWithValue("IdAutobus", mintIdAutobus)
        Command.Parameters.AddWithValue("NoEconomico", mstrNoEconomico)
        Command.Parameters.AddWithValue("IdOperador", mintIdOperador)
        Command.Parameters.AddWithValue("NombreOperador", mstrNombreOperador)
        Command.Parameters.AddWithValue("Fecha", mdatFecha)
        Command.Parameters.AddWithValue("Dia", mintDia)
        Command.Parameters.AddWithValue("Mes", mintMes)
        Command.Parameters.AddWithValue("Anio", mintAnio)
        Command.Parameters.AddWithValue("Liquidacion", mdblLiquidacion)
        Command.Parameters.AddWithValue("Optocontrol", mdblOptocontrol)
        Command.Parameters.AddWithValue("Cumplimiento", mdblCumplimiento)
        Command.Parameters.AddWithValue("Ventas", mintVentas)
        Command.Parameters.AddWithValue("Movilidad", mintMovilidad)
        Command.Parameters.AddWithValue("Bloqueos", mintBloqueos)
        Command.Parameters.AddWithValue("BloqueoPorcentaje", mdblBloqueoPorcentaje)
        Command.Parameters.AddWithValue("Total", mdblTotal)

        cnConn.Open()

        Dim RowsAffected As Integer = Command.ExecuteNonQuery

        If RowsAffected > 0 Then
            cnConn.Close()
        Else
            MsgBox("No fue posible actualizar el registro de productividad", MsgBoxStyle.Exclamation, "Aviso")
            If cnConn.State = ConnectionState.Open Then
                cnConn.Close()
            End If
        End If



    End Sub
End Class
